<?php
/**
 *问答社区话题页控制器
 */
class Commwapsubject extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('commwap_model');
    }
    /**
     *话题页信息
     */
    public function getSubById()
    {
        $post = $this->input->post();
        if (!isset($post['sid'])||!is_numeric($post['sid'])) $this->error('error: lack subject id');
        else $sid = (int)$post['sid'];
        if (!isset($post['uid'])||!is_numeric($post['uid'])) $this->error('error: lack user id');
        else $uid = (int)$post['uid'];
        $qdata  = $this->commwap_model->getSubjectById($sid,$uid);
        $this->success($qdata);
    }

    /**
     *话题页问题列表
     */
    public function getQuestionBySid()
    {
        $post = $this->input->post();
        if (!isset($post['sid'])||!is_numeric($post['sid'])) $this->error('error: lack subject id');
        else $sid = (int)$post['sid'];

        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $this->error('error: lack pagesize');
        else $limit = (int)$post['pagesize'];

        if (isset($post['page'])&&is_numeric($post['page'])) $offset = ((int)$post['page']-1)*$limit;
        else $offset = 0;

        if (isset($post['sort'])) $sort = $post['sort'];
        else $sort = 'score';

        $res = $this->commwap_model->getQuestionBysid($sid,$offset,$limit,$sort);
        $this->success($res);
    }

    public function followSub()
    {
        $sid = $this->input->input_stream('sid');
        $uid = $this->input->input_stream('uid');
        if (!isset($sid)||!is_numeric($sid)) $this->error('error: lack subject id');
        else $sid = (int)$sid;
        if (!isset($uid)||!is_numeric($uid)) $this->error('error: lack user id');
        else $uid = (int)$uid;
        $this->commwap_model->followSub($sid,$uid);
        $this->success();
    }

    public function cancelfollowSub()
    {
        $sid = $this->input->input_stream('sid');
        $uid = $this->input->input_stream('uid');
        if (!isset($sid)||!is_numeric($sid)) $this->error('error: lack subject id');
        else $sid = (int)$sid;
        if (!isset($uid)||!is_numeric($uid)) $this->error('error: lack user id');
        else $uid = (int)$uid;
        $this->commwap_model->cancelfollowSub($sid,$uid);
        $this->success();
    }


}